package com.niodata.dp.web.module.info;

import com.niodata.dp.log.LogUtil;
import java.io.IOException;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

public class BuildInfo {

  private static final Logger logger = Logger.getLogger(BuildInfo.class);
  private static BuildInfo instance;

  static {
    ResourceLoader loader = new DefaultResourceLoader();
    Resource resource =
          loader.getResource("classpath:/com/niodata/dp/web/"
                + "module/info/build/buildinfo.properties");
    Properties properties = new Properties();
    try {
      instance = new BuildInfo();
      properties.load(resource.getInputStream());
      instance.commitId = properties.getProperty("commitId").split(" ")[1];
      instance.buildTime = properties.getProperty("buildTime");
      instance.host = properties.getProperty("host");
      instance.branch = properties.getProperty("branch");
    } catch (IOException e) {
      LogUtil.logStackTrace(logger, e);
    }
  }

  String version = "0.1.5-SNAPSHOT";
  String commitId;
  String branch;
  String buildTime;
  String host;

  private BuildInfo() {
  }

  public static BuildInfo getInstance() {
    return instance;
  }

  public String getVersion() {
    return version;
  }

  public String getCommitId() {
    return commitId;
  }

  public String getBuildTime() {
    return buildTime;
  }

  public String getHost() {
    return host;
  }

  public String getBranch() {
    return branch;
  }

}
